#pragma once

#include <iostream>
#include "protocol.hpp"

class Cal
{
public:
    Response Execute(const Request& req)
    {
        Response rep(0, 0);
        int x = req.X();
        int y = req.Y();
        char op = req.OP();
        switch (op)
        {
        case '+':
            rep.SetRet(x + y);
            break;
        case '-':
            rep.SetRet(x - y);
            break;
        case '*':
            rep.SetRet(x * y);
            break;
        case '/':
            if(y == 0) rep.SetCode(1); // 除0
            else rep.SetRet(x / y);
            break;
        case '%':
            if(y == 0) rep.SetCode(2); // 余0
            else rep.SetRet(x % y);
            break;
        default:
            rep.SetCode(3); // 非法操作
            break;
        }
        return rep;
    }
};